package com.augurit.common.system.convert;

import java.util.ArrayList;
import java.util.List;

import com.augurit.common.base.extmodel.BasicCombo;
import com.augurit.common.constant.OrgConstant;
import com.augurit.common.entity.AtHomepageConfig;
import com.augurit.common.system.web.org.form.AtHomepageConfigForm;
import com.augurit.common.system.web.org.form.OmUserForm;

public class AtHomepageConfigConverter {

	public static AtHomepageConfigForm convertToForm(AtHomepageConfig entity){
		if(entity != null){
			AtHomepageConfigForm form = new AtHomepageConfigForm();

			form.setHcId(entity.getHcId());
			form.setHomepageCode(entity.getHomepageCode());
			form.setHomepageName(entity.getHomepageName());
			form.setLoadMenuLevel(entity.getLoadMenuLevel());
			form.setLoadByTree(entity.getLoadByTree());
			form.setModelName(entity.getModelName());
			form.setIsActive(entity.getIsActive());
			form.setRemark(entity.getRemark());
			
			return form;
		}
		else
			return null;
	}
	
	public static List<AtHomepageConfigForm> convertToFormList(List<AtHomepageConfig> list){
		if(list != null && list.size() > 0){
			List<AtHomepageConfigForm> result = new ArrayList();
			
			for(AtHomepageConfig entity : list){
				result.add(convertToForm(entity));
			}
			
			return result;
		}else
			return null;
	}
	
	public static void convertToEntity(AtHomepageConfigForm form, AtHomepageConfig entity){
		if(form != null && entity != null){
			
			if(form.getHcId() != null)
				entity.setHcId(form.getHcId());
			
			if(form.getHomepageCode() != null && form.getHomepageCode().trim().length() > 0)
				entity.setHomepageCode(form.getHomepageCode());
			
			if(form.getHomepageName() != null && form.getHomepageName().trim().length() > 0)
				entity.setHomepageName(form.getHomepageName());
			
			if(form.getLoadMenuLevel() != null)
				entity.setLoadMenuLevel(form.getLoadMenuLevel());
			else
				entity.setLoadMenuLevel(0);
			
			if(form.getLoadByTree() != null && form.getLoadByTree().trim().length() > 0)
				entity.setLoadByTree(form.getLoadByTree());
			else
				entity.setLoadByTree(OrgConstant.ZERO);
			
			if(form.getModelName() != null && form.getModelName().trim().length() > 0)
				entity.setModelName(form.getModelName());
			else
				entity.setModelName(OrgConstant.HOMEPAGE_MODEL_NAME_DEFAULT);
			
			if(form.getIsActive() != null && form.getIsActive().trim().length() > 0)
				entity.setIsActive(form.getIsActive());
			else
				entity.setIsActive(OrgConstant.ONE);
			
			if(form.getRemark() != null && form.getRemark().trim().length() > 0)
				entity.setRemark(form.getRemark());
		}
	}
	
	public static List<BasicCombo> convertToBasicCombo(List<AtHomepageConfigForm> list, boolean allowBlank){
		List<BasicCombo> result = new ArrayList();
		
		if(allowBlank)
			result.add(BasicCombo.getBlankItem());
		
		if(list != null && list.size() > 0){
			for(AtHomepageConfigForm form : list){
				BasicCombo combo = new BasicCombo();
				combo.setLabel(form.getHomepageCode());
				combo.setValue(form.getHomepageCode());
				result.add(combo);
			}
		}
		
		return result;
	}
}
